package com.example.apple.paopo.activity;

import android.graphics.Color;
import android.support.annotation.NonNull;
import android.support.design.widget.NavigationView;
import android.support.v4.widget.DrawerLayout;
import android.os.Bundle;
import android.view.MenuItem;
import android.view.View;
import android.widget.Toast;

import com.example.apple.paopo.R;
import com.example.apple.paopo.base.BaseActivity;
import com.example.apple.paopo.fragment.FriendsListFragment;
import com.example.apple.paopo.fragment.SessionMessageFragment;
import com.example.apple.paopo.fragment.SpaceMessageFragment;
import com.example.apple.paopo.fragment.WorldMessageFragment;
import com.example.apple.paopo.library.TabItem;
import com.example.apple.paopo.library.XFragmentTabHost;
import com.orhanobut.logger.Logger;
import com.vondear.rxtools.view.RxToast;

import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
import org.xutils.view.annotation.ContentView;
import org.xutils.view.annotation.ViewInject;
import org.xutils.x;

@ContentView(R.layout.activity_main)
public class MainActivity extends BaseActivity {

    @ViewInject(R.id.main_navigationView)
    private NavigationView navigationView;

    @ViewInject(R.id.activity_main)
    private DrawerLayout drawerLayout;

    // 定义FragmentTabHost对象
    @ViewInject(android.R.id.tabhost)
    private XFragmentTabHost mTabHost;

    String[] mTabTitle = new String[] {"世界", "空间", "会话", "好友"};
    int[] mImageResId = new int[] {R.drawable.sel_menu_shijie, R.drawable.kongjian, R.drawable.sel_menu_huihua,
            R.drawable.sel_menu_haoyou};
    Class[] mFragClass = new Class[] {WorldMessageFragment.class, SpaceMessageFragment.class,
            SessionMessageFragment.class, FriendsListFragment.class};

    private void initTabHost() {
        mTabHost.setup(this, getSupportFragmentManager(), R.id.relate_tab_content);
        mTabHost.setTabMode(XFragmentTabHost.TabMode.Ripple);
        mTabHost.setTextActiveColor(Color.WHITE);
        mTabHost.setTextInactiveColor(Color.GRAY);
        mTabHost.setFrontColor(Color.rgb(00,191,255));
        mTabHost.setBehindColor(Color.rgb(118,195,238));

        for (int i = 0; i < mTabTitle.length; i++) {
            mTabHost.addTabItem(new TabItem(mTabTitle[i], mImageResId[i]),
                    mFragClass[i],null);
        }
    }

//    @Subscribe(threadMode = ThreadMode.MAIN,sticky = true)
//    public void onMessageEvent(String string) {
//        Logger.d(string);
//        RxToast.success(string);
//    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        x.view().inject(this);
        initTabHost();
        View headerView = navigationView.getHeaderView(0);//获取头布局
        navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
            @Override
            public boolean onNavigationItemSelected(@NonNull MenuItem item) {
                //item.setChecked(true);
                Toast.makeText(MainActivity.this,item.getTitle().toString(),Toast.LENGTH_SHORT).show();
                drawerLayout.closeDrawer(navigationView);
                return true;
            }
        });
    }
}
